import { expect, test } from "vitest"
import { classifyChangePoint, getChangePointIndexes } from "../../src/shared/changeDetector/algorithm"

test("complex queries are not merged", () => {
  expect(
    getChangePointIndexes([
      5691, 5855, 5720, 6339, 5829, 5496, 5427, 5586, 5859, 5603, 5868, 5761, 5440, 5590, 5870, 5781, 5632, 6092, 5636, 5849, 5730, 5639, 5678, 5857, 5655, 5486, 5877, 5639, 5668,
      5864, 5602, 5855, 6049, 5741, 5794, 5822, 5704, 5707, 6167, 5923, 5765, 5648, 5775, 5578, 5541, 5919, 5498, 5436, 5857, 5508, 5739, 5820, 5662, 5582, 5565, 5708, 5587, 5813,
      5618, 5796, 5682, 5778, 5848, 6034, 5847, 5653, 5783, 6006, 5647, 5509, 5869, 5738, 5709, 5762, 5793, 5607, 5620, 5580, 5710, 5641, 5673, 5794, 5937, 5708, 5705, 5747, 5679,
      5963, 6240, 5958, 5915, 5737, 6000, 5747, 5529, 5562, 5909, 5713, 5680, 5729, 5656, 5820, 5670, 5884, 5686, 5662, 5848, 5710, 5707, 5821, 5564, 6029, 6045, 5765, 5727, 5653,
      5766, 5784, 5893, 5755, 5756, 5836, 5652, 5971, 6000, 5689, 6110, 5953, 6102, 5747, 5872, 5808, 5891, 5839, 5719, 5865, 6114, 5811, 5687, 5834, 5759, 5873, 6114, 6314, 5757,
      5849, 5901, 5993, 5226, 5338, 5356, 5299, 5426, 5479, 5687, 5594, 5497, 5735, 19094, 19217, 19264, 18976, 19040, 19348, 19092, 5777, 5810, 5636, 5600, 5681, 5528, 5573, 5494,
      5613, 5603, 5509, 5455, 5552, 5773, 5903, 5385,
    ])
  ).toStrictEqual([111, 148, 153, 158, 165])
})

test("check estimator", () => {
  const dataset = [
    662, 627, 297, 412, 608, 263, 284, 294, 295, 153, 635, 423, 720, 509, 159, 169, 479, 403, 572, 225, 642, 598, 277, 294, 170, 645, 187, 187, 693, 176, 695, 283, 270, 524, 605,
    169, 302, 575, 217, 307, 301, 639, 173, 698, 186, 693, 300, 672, 293, 674, 170, 192, 154, 652, 686, 677, 677, 306, 627, 368, 602, 291, 534, 178, 296, 627, 285, 695, 162, 152,
    610, 655, 525, 262, 339, 622, 605, 174, 321, 312, 294, 274, 279, 294, 282, 230, 590, 640, 460, 296, 313, 670, 521, 298, 152, 456, 214, 291, 280, 161, 352, 288, 620, 160, 199,
    304, 153, 318, 169, 281, 694, 310, 637, 300, 280, 172, 309, 151, 177, 154, 647, 309, 334, 614, 281, 319, 665, 673, 290, 292, 296, 279, 395, 156, 602, 560, 612, 373, 310, 306,
    289, 154, 334, 285, 284, 155, 313, 294, 570, 616, 280, 632, 553, 231, 631, 301, 288, 289, 157, 268, 644, 591, 511, 242, 197, 209, 591, 224, 315, 705, 616, 187, 558, 163, 619,
    204, 511, 308, 198, 178, 180, 616, 285, 289, 212, 174, 448, 642, 695, 280, 597, 586, 298, 623, 619, 875, 316, 643, 291, 627, 693, 299, 184, 210, 460, 432, 158, 678, 437, 483,
    603, 673, 290, 173, 270, 281, 285, 624, 156, 286, 286, 640, 283, 301, 296, 215, 483, 610, 558, 281, 295, 288, 627, 289, 156, 287, 277, 281, 355, 637, 225, 285, 620, 644, 280,
    601, 299, 640, 614, 222, 495, 280, 399, 295, 283, 537, 286, 300, 327, 353, 671, 692, 565, 255, 683, 633, 673, 152, 281, 569, 285, 697, 637, 638, 688, 463, 636, 642, 288, 318,
    357, 348, 293, 684, 299, 578, 291, 551, 325, 305, 563, 192, 628, 206, 553, 209, 164, 148, 313, 279, 604, 602, 319, 434, 669, 169, 188, 276, 155, 552, 284, 318, 703, 604, 467,
    285, 678, 296, 657, 597, 607, 170, 275, 347, 278, 283, 285, 594, 645, 286, 599, 170, 280, 436, 564, 690, 632, 591, 289, 602, 684, 701, 308, 324, 393, 282, 663, 295, 547, 570,
    488, 187, 512, 245, 569, 163, 623, 343, 645, 634, 190, 283, 191, 153, 655, 290, 288, 614, 144, 615, 523, 291, 226, 162, 284, 469, 298, 297, 525, 530, 275, 299, 290, 448, 694,
    297, 341, 556, 531, 187, 632, 628, 288, 586, 286, 293, 630, 275, 286, 543, 274, 581, 573, 278, 465, 294, 289, 287, 328, 319, 604, 293, 297, 333, 504, 317, 150, 305, 689, 654,
    233, 152, 292, 158, 607, 156, 683, 295, 151, 171, 339, 352, 655, 605, 433, 281, 150, 771, 149, 285, 599, 330, 585, 287, 717, 624, 291, 610, 280, 314, 289, 235, 646, 668, 611,
    477, 160, 465, 558, 350, 150, 295, 341, 299, 670, 285, 167, 299, 170, 286, 293, 318, 474, 284, 285, 152, 295, 330, 283, 283, 293, 284, 280, 646, 571, 162, 283, 590, 640, 289,
    668, 359, 630, 172, 589, 288, 587, 160, 278, 559, 592, 315, 298, 154, 312, 599, 192, 302, 604, 359, 327, 241, 321, 287, 326, 277, 283, 311, 295, 243, 424, 352, 677, 412, 203,
    147, 194, 721, 726, 755, 610, 763, 183, 618, 479, 528, 746, 754, 763, 468, 700, 593, 718, 599, 587, 296, 756, 634, 697, 632, 220, 745, 272, 389, 348, 303, 553, 163, 334, 432,
    598, 683, 286, 281, 287, 651, 286, 642, 684, 644, 185, 425, 469, 604, 490, 286, 182, 305, 499, 280, 595, 287, 204, 304, 687, 478, 300, 308, 216, 584, 176, 288, 666, 395, 591,
    485, 494, 656, 528, 280, 616, 296, 168, 609, 289, 152, 630, 300, 689, 630, 279, 437, 327, 357, 414, 283, 662, 277, 296, 298, 635, 290, 695, 315, 179, 154, 464, 677, 284, 300,
    510, 287, 283, 282, 284, 407, 171, 609, 285, 276, 657, 338, 534, 619, 165, 151, 300, 279, 613, 494, 223, 287, 279, 145, 283, 300, 191, 297, 311, 644, 298, 577, 577, 239, 287,
    170, 157, 147, 293, 464, 389, 521, 308, 552, 315, 479, 277, 294, 670, 191, 412, 392, 402, 284, 294, 285, 272, 525, 646, 315, 459, 284, 620, 324, 197, 679, 571, 650, 292, 565,
    169, 165, 554, 649, 344, 359, 552, 546, 626, 278, 543, 348, 286, 182, 308, 633, 273, 167, 640, 283, 279, 675, 147, 358, 161, 284, 550, 455, 651, 378, 176, 473, 549, 612, 310,
    377, 588, 157, 371, 635, 292, 304, 670, 358, 301, 148, 287, 610, 285, 702, 277, 700, 307, 639, 556, 607, 479, 348, 291, 313, 286, 173, 553, 274, 364, 652, 717, 661, 280, 453,
    280, 303, 297, 300, 543, 659, 443, 314, 289, 184, 515, 298, 290, 475, 599, 276, 160, 304, 155, 661, 286, 591, 300, 615, 440, 295, 619, 514, 590, 579, 333, 296, 298, 498, 512,
    629, 664, 154, 181, 675, 628, 156, 171, 583, 672, 151, 282, 160, 596, 321, 299, 294, 604, 304, 163, 571, 739, 762, 602, 499, 201, 706, 643, 707, 690, 650, 713, 365, 295, 549,
    571, 203, 309, 485, 304, 703, 291, 608, 594, 332, 321, 329, 682, 530, 613, 291, 279, 627, 563, 447, 524, 637, 298, 444, 310, 538, 629, 649, 684, 300, 302, 296, 638, 652, 288,
    661, 346, 651, 636, 298, 300, 295, 304, 512, 303, 535, 681, 722, 526, 586, 321, 706, 317, 685, 635, 299, 291, 529, 589, 621, 364, 468, 611, 441, 302, 299, 292, 591, 513, 286,
    200, 245, 304, 599, 698, 569, 306, 457, 231, 464, 320, 309, 300, 307, 704, 277, 297, 309, 531, 327, 575, 563, 311, 665, 703, 674, 520, 645, 677, 673, 361, 627, 696, 309, 584,
    553, 531, 602, 626, 634,
  ]
  const changePoints = getChangePointIndexes(dataset, 30)
  const classified = classifyChangePoint(changePoints, dataset)

  expect(classified).toStrictEqual(["No Change", "No Change", "No Change"])
})
